package com.ntv.presentation.spring.web.home;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.ntv.common.NewsCategory;
import com.ntv.domain.INews;
import com.ntv.service.flashnews.IFlashNewsAppService;
import com.ntv.service.news.INewsAppService;
@Controller
@RequestMapping("/home.htm")
public class MainController
{
	
	private static final Logger logger = Logger.getLogger(MainController.class);
	
	@Autowired
	private INewsAppService newsAppService;
	
	@Autowired
	private IFlashNewsAppService flashNewsAppService;
	
	
	public void setNewsAppService(INewsAppService newsAppService) {
		this.newsAppService = newsAppService;
	}

	public void setFlashNewsAppService(IFlashNewsAppService flashNewsAppService) {
		this.flashNewsAppService = flashNewsAppService;
	}
	
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView form(Model modelll) throws Exception {
		List<INews> flashNewsList = flashNewsAppService.getCurrentDayFlashNews();
		
		Map model = newsAppService.getHomePageNewsObject();
		//model.put(NewsType.NATIONAL.getDescription(), nationalNewsList);
		model.put("FlashNewsList", flashNewsList);
		model.put("newsCategories", NewsCategory.values());
		
		ModelAndView mav = new ModelAndView("main", model );
		return mav;
	}
	/*
	public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception 
	{
		List<INews> nationalNewsList = newsAppService.getNataionNewsList();
		List<INews> flashNewsList = flashNewsAppService.getCurrentDayFlashNews();
		
		Map model = newsAppService.getHomePageNewsObject();
		//model.put(NewsType.NATIONAL.getDescription(), nationalNewsList);
		model.put("FlashNewsList", flashNewsList);
		model.put("newsCategories", NewsCategory.values());
		
		ModelAndView mav = new ModelAndView("main", model );
		return mav;
	}*/
}
